---
title: Chatbot
sidebarTitle: Chatbot
---

Within MindsDB, chatbots are [agents](/agents/agent) connected to some messaging interface.

Creating a chatbot requires an [AI agent](/agents/agent) and a connection to a chat app, like [Slack](/integrations/app-integrations/slack) or [MS Teams](/integrations/app-integrations/microsoft-teams).

<Tip>
Currently, the recommended chat app is Slack. MS Teams will be fully supported soon.
</Tip>

<p align="center">
  <img src="/assets/chatbot_diagram.png" />
</p>

## How to work with chatbots

A chatbot can be created, deleted, queried, and updated. Here is how you can do that using SQL API.

* Creating a chatbot:

    ```sql
    CREATE CHATBOT my_chatbot
    USING
        database = 'my_slack', -- this must be created with CREATE DATABASE
        agent = 'customer_support_agent', -- this must be created with CREATE AGENT
        included_channels = ['support', 'help'], -- Default is all
        excluded_channels = [], -- Default is none
        enable_dms = true,
        is_running = true; -- Default is true
    ```

    The parameters include the following:

    * `database` stores connection to a chat app (like [Slack](/integrations/app-integrations/slack) or [MS Teams](/integrations/app-integrations/microsoft-teams)) that should be created with the `CREATE DATABASE` statement.
    * `agent` is an [AI agent](/agents/agent) created with the `CREATE AGENT` command. It consists of an AI model trained with defined data sets.
    * `included_channels` and `excluded_channels` are optional and store channel names where the bot will or will not respond.
    * `enable_dms` is the initially supported mode of talking to a chatbot. A chatbot responds to direct messages.
    * `is_running` indicates whether or not to start the chatbot upon creation.

    <Note>
    If you want to use Slack in the [`CREATE CHATBOT`](/agents/chatbot) syntax, use [this method of connecting Slack to MindsDB](/integrations/app-integrations/slack#method-1-chatbot-responds-in-direct-messages-to-a-slack-app).
    </Note>

* Deleting a chatbot:

    ```sql
    DROP CHATBOT my_chatbot;
    ```

You can query all chatbots using these commands:

```sql
SELECT * FROM chatbots;
```

## Example

Following the example from [here](/agents/agent#example), let's create a chatbot utilizing the already created agent.

Start by connecting a chat app to MindsDB:

* Follow [this instruction](/integrations/app-integrations/slack) to connect Slack to MindsDB.
* Follow [this instruction](/integrations/app-integrations/microsoft-teams) to connect MS Teams to MindsDB.

Next, create a chatbot.

```sql
CREATE CHATBOT text_to_sql_chatbot
USING
    database = 'my_slack', -- this must be created with CREATE DATABASE
    agent = 'text_to_sql_agent', -- this must be created with CREATE AGENT
    enable_dms = true,
    is_running = true;
```

<Tip>
To create `my_slack` and be able to talk to the chatbot via DMs, follow [this instruction](https://docs.mindsdb.com/integrations/app-integrations/slack#method-1-chatbot-responds-in-direct-messages-to-a-slack-app).

To see how the agent is created, follow [this example](/agents/agent#example).
</Tip>
